/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić   				       			   *
 *   ivasic@gmail.com   								   				   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef _CONNECTION_DB_H
#define _CONNECTION_DB_H
		
#include <QtSql>
#include <QtCore>
#include <QDebug>

		
static bool createConnection()
{
    QSqlDatabase db = QSqlDatabase::addDatabase(DB_DRIVER);
    
	db.setDatabaseName(DB_NAME);
	db.setHostName(DB_HOST);
	db.setUserName(DB_USERNAME);
	db.setPassword(DB_PASSWORD);
    //db.setPort(DB_PORT);
	
    if (!db.open()) 
	{
		qDebug() << db.lastError().text();
     /*   QMessageBox::critical(0, qApp->tr("Cannot open database"),
            qApp->tr("Unable to establish a database connection.\n"
                     "Click Cancel to exit."), QMessageBox::Cancel);*/
        return false;
    }
	
	//Create dummy table to know if database exists and is valid.
	/*query.exec("CREATE TABLE dummy (id INTEGER PRIMARY KEY)");
	query.exec("INSERT INTO dummy VALUES (NULL)");
	
	//Create tables
	query.exec("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, number TEXT");
	*/
    return true;
}

#endif

